Skip to content

fix(core): Inject replayId into trace context for buffer mode errors#5754

Open
romtsn wants to merge 5 commits into
rz/fix/replay-segment-id-normalizationfrom
rz/fix/replay-error-linkage
Open

fix(core): Inject replayId into trace context for buffer mode errors#5754
romtsn wants to merge 5 commits into
rz/fix/replay-segment-id-normalizationfrom
rz/fix/replay-error-linkage

Conversation

@romtsn

@romtsn romtsn commented Jul 10, 2026

Copy link
Copy Markdown
Member

📜 Description

In buffer mode, the scope's replayId is intentionally empty until captureReplay() is called (to avoid tagging events with a replay that may never be sent). However, the event's DSC is built from the active transaction's frozen baggage, which was frozen before captureReplay() set the replayId. This means error events that trigger a buffer replay flush have no replay_id in their DSC, breaking error-to-replay linkage.

After captureReplay() runs, we now force-set the replayId on the transaction's frozen baggage via Baggage.forceSetReplayId(), so the envelope header carries the correct replay_id in the DSC. This mirrors the JS SDK's setReplayIdOnDynamicSamplingContext.

💡 Motivation and Context

Error events that trigger buffer-mode replay capture were not linked to the resulting replay, making it impossible to navigate from the error to its replay in the Sentry UI.

Example replay with a linked error event: https://sentry-sdks.sentry.io/explore/replays/49e737e2f6dc48f1a9c14692bd898bb7/?playlistEnd=2026-07-13T07:15:41&playlistStart=2026-07-06T07:15:41&project=5428559&query=&referrer=replayList&t_main=errors

💚 How did you test it?

  • Existing SentryClientTest suite passes
  • Manual verification with sample app in buffer mode: captured exception's DSC now contains the replay_id, and the error appears linked to the replay in Sentry

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.

🔮 Next steps

@sentry

sentry Bot commented Jul 10, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.48.0 (1) release

⚙️ sentry-android Build Distribution Settings

@github-actions

github-actions Bot commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 319.82 ms 356.96 ms 37.14 ms
Size 0 B 0 B 0 B

Baseline results on branch: rz/fix/replay-segment-id-normalization

Startup times

Revision Plain With Sentry Diff
39e4c55 352.43 ms 446.94 ms 94.51 ms
048e40b 322.47 ms 362.69 ms 40.22 ms
94ec28b 317.49 ms 407.84 ms 90.35 ms
a5d4b7b 413.28 ms 506.54 ms 93.26 ms

App size

Revision Plain With Sentry Diff
39e4c55 0 B 0 B 0 B
048e40b 0 B 0 B 0 B
94ec28b 0 B 0 B 0 B
a5d4b7b 0 B 0 B 0 B

Previous results on branch: rz/fix/replay-error-linkage

Startup times

Revision Plain With Sentry Diff
7dd24bc 315.35 ms 363.57 ms 48.22 ms
4f9605b 382.72 ms 476.24 ms 93.52 ms
9fbe087 391.26 ms 480.70 ms 89.44 ms
48dcd0f 322.68 ms 374.14 ms 51.46 ms
01678a6 315.83 ms 347.92 ms 32.09 ms
e6285ac 315.38 ms 353.88 ms 38.50 ms

App size

Revision Plain With Sentry Diff
7dd24bc 0 B 0 B 0 B
4f9605b 0 B 0 B 0 B
9fbe087 0 B 0 B 0 B
48dcd0f 0 B 0 B 0 B
01678a6 0 B 0 B 0 B
e6285ac 0 B 0 B 0 B

@romtsn romtsn changed the base branch from main to rz/fix/replay-segment-id-normalization July 10, 2026 13:02
In buffer mode, the scope's replayId is empty until captureReplay()
is called. The transaction's baggage is frozen before that, so the
DSC in the envelope header has no replay_id — breaking error-to-replay
linkage.

After captureReplay() sets the replayId on scope, force-set it on
the transaction's frozen baggage via Baggage.forceSetReplayId() so
the envelope header carries the correct replay_id in the DSC. This
matches the JS SDK's approach of updating the DSC after buffer-to-
session conversion.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@romtsn romtsn force-pushed the rz/fix/replay-error-linkage branch from 43dceab to 8c8db4b Compare July 10, 2026 13:07
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@romtsn romtsn force-pushed the rz/fix/replay-error-linkage branch from e63a32e to 6f89328 Compare July 10, 2026 13:35
Comment thread CHANGELOG.md Outdated
romtsn and others added 2 commits July 13, 2026 09:14
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@romtsn romtsn marked this pull request as ready for review July 13, 2026 09:28
Comment thread sentry/src/main/java/io/sentry/SentryClient.java

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit aab9e17. Configure here.

Comment thread sentry/src/main/java/io/sentry/SentryClient.java Outdated
@romtsn romtsn force-pushed the rz/fix/replay-error-linkage branch from aab9e17 to 64766b2 Compare July 13, 2026 09:40
Read scope.getReplayId() which is only set when on-error sampling
succeeds. Using ReplayController.getReplayId() would return the
buffer's internal ID even when sampling rejected the replay.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@romtsn romtsn force-pushed the rz/fix/replay-error-linkage branch from 64766b2 to fa65f2e Compare July 13, 2026 09:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants